package com.huawei.hwid.core.d;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import com.huawei.hwid.b.b;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.d.a;
import java.io.IOException;
import java.util.Date;

public class h {
    public static boolean a(Context context) {
        long parseLong;
        e.b("GlobalDownloadUtil", "check needUpdateProp ", true);
        try {
            parseLong = Long.parseLong(a.a(context).b().r());
        } catch (NumberFormatException e) {
            parseLong = 0;
        } catch (Exception e2) {
            parseLong = 0;
        }
        long time = new Date().getTime();
        if (parseLong > time) {
            parseLong = 0;
        }
        if (parseLong == 0 || time - parseLong > HwAccountConstants.CHECK_SITE_COUNTRY_DURATION) {
            e.b("GlobalDownloadUtil", "need check prop", true);
            return true;
        }
        e.b("GlobalDownloadUtil", "no need check prop", true);
        return false;
    }

    public static void a(Context context, Handler handler) throws IOException {
        if (a(context)) {
            new Thread(new 1(context, handler)).start();
        }
    }

    public static boolean b(Context context, Handler handler) throws IOException {
        e.b("GlobalDownloadUtil", "Start syn download global.", true);
        Object a = b.a.a(context, "", "Root");
        e.b("GlobalDownloadUtil", "asUrl from Grs::=" + a, false);
        if (TextUtils.isEmpty(a)) {
            e.b("GlobalDownloadUtil", "globalHost is null", true);
            if (handler != null) {
                handler.sendEmptyMessage(10001);
            }
            throw new IOException("globalHost is null");
        }
        com.huawei.hwid.core.b.a.a aVar = new com.huawei.hwid.core.b.a.a.a(context, a);
        com.huawei.hwid.core.b.a.e.a(context, aVar, null);
        if (200 != aVar.f() || aVar.g() != 0) {
            return false;
        }
        e.b("GlobalDownloadUtil", "downloadGlobalCountrySiteBackgroundImmediately Succ", true);
        if (handler == null) {
            return true;
        }
        handler.sendEmptyMessage(10001);
        return true;
    }
}
